* Hedonic_models.do
* 2014.12.01
* Last update 2014.12.05: revised to reflect new instrument
* Estimates hedonic models to check instrument validity

capture log close
set more off
timer clear 1
timer on 1
clear

local work "/DIRECTORY"

log using "`work'/logs/Hedonic_models.log", replace
set matsize 11000

* Flow control
local main = 1
local robustness = 1
local output = 1

* Reading data
use "`work'/data/hedonic/Hedonic.dta", clear

* Additional variables
gen lnval = log(median)
drop lat_merge
mkspline lat_ 10 = latitude
mkspline pd_ 5 = pop_density
mkspline cd_ 3 = coast_dist
label variable lnval "Log value"
label variable sunset_time "Sunset time"

/////////////////////////////////
// Locals for sets of controls
/////////////////////////////////
local geographic = "coast_dist coast cc lat_*"
local demographic = "median_age_2010 pct_female_2010 pct_black_2010 pct_asian_2010 pct_white_2010 pd_* occ_*" /* pct_lessthan9thgr pct_gr9to12 pct_HSgrad pct_some_college pct_BA_BS */

* Locals for variable sets
local con1 "latitude area_km i.st i.rural_urban_continuum_20013"
local con2 "pop_2010 net_mig_2010 n_pop_chg_2010"
local con3 "pct_lhs_2006_2010 pct_hs_2006_2010 pct_scollege_2006_2010 pct_college_2006_2010 unemployment_rate_2010 civilian_labor_force_2010"
local con4 "medhhinc_2011 international_mig_2010"

if `main' == 1 {
	* Models
	eststo clear
	eststo: reg lnval `geographic' sunset_time, vce(robust)
	eststo: reg lnval `geographic' `demographic' sunset_time, vce(robust)
	if `output'==1 {
	esttab using "`work'/tables/Hedonic.tex", keep(sunset_time) ///
		indicate("Geographic controls=`geographic'" "Demographic controls=`demographic'") ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		ar2 se label tex fragment nonumbers nogaps replace
	} /* End output conditional */
	* Model in levels for back-of-envelope
	reg median `geographic' sunset_time, vce(robust)
	reg median `geographic' `demographic' sunset_time, vce(robust)
}

if `robustness' == 1 {
	eststo clear
	eststo: reg lnval `geographic' `demographic' sunset_time, vce(robust)
	eststo: reg lnval `geographic' `demographic' naics_* sunset_time, vce(robust)
	eststo: reg lnval `geographic' `demographic' `con3' sunset_time, vce(robust)
	eststo: reg lnval `geographic' longitude `demographic' sunset_time, vce(robust)
	if `output'==1 {
	esttab using "`work'/tables/Hedonic_robustness.tex", keep(sunset_time) ///
		indicate("Base controls=`geographic' `demographic'" "Industry shares=naics_*" "Educational attainment=pct_*" "Longitude=longitude") ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		ar2 se label tex fragment nonumbers nogaps replace
	} /* End output conditional */
}

timer off 1
timer list 1
capture log close





